package cn.lsngo.manager;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.lsngo.manager.greendao.ElectricBean;

/**
 * @author : admin
 * @Title :
 * @date : 2021/12/23 15:03
 */
public class HistoryListActivity extends AppCompatActivity {

    private RecyclerView mRecycler;
    private List<ElectricBean> mList = new ArrayList<>();
    private HistoryListAdapter mAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history_list);
        mRecycler = (RecyclerView) findViewById(R.id.recycler_view);
        LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mRecycler.setLayoutManager(manager);
        mAdapter = new HistoryListAdapter(this, mList);
        mRecycler.setAdapter(mAdapter);
        mAdapter.setOnClick(position -> {
            Long id = mList.get(position).getId();
            Intent intent = new Intent(HistoryListActivity.this, HistoryActivity.class);
            intent.putExtra(Constants.IntentInfo, id);
            startActivity(intent);
        });

        queryData();

    }

    private void queryData() {
        List<ElectricBean> electricBeans = DataModule.queryAllElectric();
        if (electricBeans != null && electricBeans.size() > 0) {
            mList.addAll(electricBeans);
        }
        mAdapter.setList(mList);
    }
}
